package com.itheima.ticket.mai2;

public class Ticket implements Runnable {
    private int count = 100;
    private Object obj = new Object();

    @Override
    public void run() {
        //完成卖票操作
        while (true) {
            String name = Thread.currentThread().getName();
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (obj) {
                if (count > 0) {
                    count--;
                    System.out.println(name + "卖了一张还剩" + count + "张票");
                } else {
                    break;
                }
            }
        }
    }
}
